import request from '@/utils/request';
import { download, toFormData, checkDownloadRes } from '@/utils/common';

/**
 * 分页查询纸管收费
 */
export async function pageMesPaperTubeChargess(params) {
  const res = await request.get('/mes/mesPaperTubeCharges/list', { params });
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询全部纸管收费
 */
export async function listMesPaperTubeChargess(params) {
  const res = await request.get('/mes/mesPaperTubeCharges/list', { params });
  if (res.data.code === 200) {
    return res.data.rows;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id查询纸管收费
 */
export async function getMesPaperTubeCharges(id) {
  const res = await request.get('/mes/mesPaperTubeCharges/' + id);
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加纸管收费
 */
export async function addMesPaperTubeCharges(data) {
  const res = await request.post('/mes/mesPaperTubeCharges', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改纸管收费
 */
export async function updateMesPaperTubeCharges(data) {
  const res = await request.put('/mes/mesPaperTubeCharges', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除纸管收费
 */
export async function removeMesPaperTubeCharges(id) {
  const res = await request.delete('/mes/mesPaperTubeCharges/' + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除纸管收费
 */
export async function removeMesPaperTubeChargess(ids) {
  const res = await request.delete('/mes/mesPaperTubeCharges/' + ids.join());
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 导出纸管收费
 */
export async function exportMesPaperTubeChargess(params) {
  const res = await request({
    url: '/mes/mesPaperTubeCharges/export',
    method: 'POST',
    data: toFormData(params),
    responseType: 'blob'
  });
  await checkDownloadRes(res);
  download(res.data, `mesPaperTubeCharges_${Date.now()}.xlsx`);
}
